#ifndef IO_FILTER_H
#define IO_FILTER_H
#include "message_context.h"
#include <boost/shared_ptr.hpp>
namespace vpm
{
	namespace mina
	{

		enum FilterType
		{
			CHAIN_NONE_FILTER=0,
			CHAIN_IN_FILTER,
			CHAIN_OUT_FILTER,		
		} ;

		enum FilterAction
		{
			FILTER_CONTINUE, // move onto the next Processor
			FILTER_WAIT_EVENT, // stop Processor chain and wait for async response
			FILTER_SKIP_THIS_CHAIN,
			FILTER_SKIP_ALL_CHAINS,
		};


		class IoFilter
		{
		public:
			
			IoFilter(FilterType type = CHAIN_NONE_FILTER):m_filterType(type)
			{

			}
			
			virtual ~IoFilter()
			{
			}

			virtual FilterAction process(MessageContext & )= 0; 


			void filter_type(FilterType type)
			{
				m_filterType = type; 
			}

			FilterType filter_type()
			{
				return m_filterType; 
			}

            void next_filter(boost::shared_ptr<IoFilter>& filter)  //append to last filter 
            {
                boost::shared_ptr<IoFilter> lastFilter = m_nextFilter; 
                while (lastFilter && lastFilter->next_filter())
                {
                    lastFilter = lastFilter->next_filter(); 
                }
                lastFilter->next_filter(filter); 
            }

            boost::shared_ptr<IoFilter> & next_filter()
            {
                return m_nextFilter; 
            }
		private:
			FilterType m_filterType; 
            boost::shared_ptr<IoFilter> m_nextFilter ; 

		};

        typedef boost::shared_ptr<IoFilter> IoFilterPtr; 
	}
}


#endif // IO_FILTER_H
  
